package cpr.command;

import java.util.Iterator;

import cpr.DefaultCommandHandler;
import cpr.Printer;
import cpr.context.Context;

public class CmdSetProperty extends DefaultCommandHandler {
	public CmdSetProperty() {
		super("set");
	}
	public void execute(String[] params) throws Exception {
			String name = getParameter(params, 1);
			String value = getParameter(params, 2);
			Context ctx = getCommandContext().getContext();
			if (name!=null) {
				ctx.setProperty(name,value);
			} else {
				// displaying available properties
				for (Iterator iter = ctx.getPropertyKeys().iterator(); iter.hasNext();) {
					String pkey = (String) iter.next();
					Object pval = ctx.getProperty(pkey);
					Printer.println(pkey+" = "+pval);
				}
			}
		
	}
}
